<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width: 100%">
    <el-col>
      <span>{{ treeData.name }}</span>
    </el-col>
    <el-col :span="6">
      <el-row type="flex" justify="space-between">
        <!-- 两个内容 -->
        <el-col>
          <span>{{ treeData.manager }}</span>
        </el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('addDept',treeData)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="$emit('editDept',treeData)">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'
export default {
  // props可以用数组来接收数据 也可以用对象来接收
  // props: {   props属性: {  配置选项 }  }
  name: 'TreeList',
  props: {
    //   定义一个props属性
    // 当前节点的信息
    treeData: {
      type: Object,
      default: () => ({})
    },
    isRoot: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      key: ''
    }
  },
  methods: {
    async del() {
      await this.$confirm('确定删除吗？')
      await delDepartments(this.treeData.id)
      this.$message.success('删除成功')
      this.$emit('update')
    }
  }
}
</script>
